{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Solution(object):\n",
    "    def findRadius(self, houses, heaters):\n",
    "        \"\"\"\n",
    "        :type houses: List[int]\n",
    "        :type heaters: List[int]\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        heaters = sorted(heaters) + [2**31]\n",
    "        i = r = 0\n",
    "        for x in sorted(houses):\n",
    "            while x >= ((heaters[i] + heaters[i+1]) / 2.):\n",
    "                i += 1\n",
    "            r = max(r, abs(heaters[i] - x))\n",
    "            \n",
    "        return r        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "s = Solution()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.findRadius([1,2,3,4],[1,4])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
